#include "EpilLocalVariableStatementCode.h"
#include "EpilOutputHelper.h"
#include "EpilParserException.h"
#include <stdexcept>
#include <algorithm>
#include "EpilPointerHelper.h"

using namespace std;


EpilLocalVariableStatementCode::EpilLocalVariableStatementCode( const EpilLexLocation & location )
: EpilStatementCodeBase( location )
{
}


EpilLocalVariableStatementCode::~EpilLocalVariableStatementCode()
{
	EpilPointerHelper::DeleteItemsAndClear( m_assigners );
}


tstring EpilLocalVariableStatementCode::ToEpilCode( int indent ) const
{
	tstringstream ret;
	ret << EpilOutputHelper::GetIndent( indent );

	ret << t("local ");

	if( m_variables.empty() )
	{
		throw runtime_error( "No variable?!" );
	}
	ret << EpilOutputHelper::GetListOutput( m_variables, t(", ") );

	if( m_assigners.empty() )
	{
		return ret.str();
	}
	else
	{
		ret << t(" = ");
		ret << EpilOutputHelper::GetListOutput( m_assigners, t(", ") );
	}

	return ret.str();
}